﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

#if WPF
using EventArgs = System.Windows.RoutedEventArgs;

namespace Silverlight.Hosting.Wpf
#else
namespace Silverlight.Hosting
#endif
{
    /// <summary>
    /// Describes a run-time error.
    /// </summary>
    public class RuntimeErrorEventArgs : ErrorEventArgs
    {
        /// <summary>
        /// Gets the character position within the line on which the parser error occurred.
        /// </summary>
        public int CharPosition { get; internal set; }
        /// <summary>
        /// Gets the line number at which the parser error occurred.
        /// </summary>
        public int LineNumber { get; internal set; }
        /// <summary>
        /// Gets the name of the method that is associated with a run-time error.
        /// </summary>
        public string MethodName { get; internal set; }

        internal RuntimeErrorEventArgs()
        {
        }
    }

    /// <summary>
    /// Describes a XAML parser error.
    /// </summary>
    public class ParserErrorEventArgs : ErrorEventArgs
    {
        /// <summary>
        /// Gets the character position within the line on which the parser error occurred.
        /// </summary>
        public int CharPosition { get; internal set; }
        /// <summary>
        /// Gets the line number at which the parser error occurred.
        /// </summary>
        public int LineNumber { get; internal set; }
        /// <summary>
        /// Gets the name of the XAML file in which a parser error occurred.
        /// </summary>
        public string XamlFile { get; internal set; }
        /// <summary>
        /// Gets the XML attribute in which a parser error occurred.
        /// </summary>
        public string XmlAttribute { get; internal set; }
        /// <summary>
        /// Gets the XML element in which a parser error occurred.
        /// </summary>
        public string XmlElement { get; internal set; }

        internal ParserErrorEventArgs()
        {
        }
    }

    /// <summary>
    /// Describes a XAML parse error or a run-time error at the native-code level.
    /// </summary>
    public class ErrorEventArgs : EventArgs
    {
        /// <summary>
        /// Gets the error code that is associated with an error.
        /// </summary>
        public int ErrorCode { get; internal set; }
        /// <summary>
        /// Gets the error description that is associated with an error.
        /// </summary>
        public string ErrorMessage { get; internal set; }
        /// <summary>
        /// Gets the ErrorType of the error that is associated with an event.
        /// </summary>
        public ErrorType ErrorType { get; internal set; }
        /// <summary>
        /// Gets or sets a unique identification for the object. A Name can be set
        /// only during the initial parsing of XAML; it is not settable in scripting.
        /// </summary>
        public string Name { get; internal set; }

        internal ErrorEventArgs()
        {
        }
    }

    public class SilverlightEventArgs : EventArgs
    {
        /// <summary>
        /// Gets the name of the event.
        /// </summary>
        public string Name { get; internal set; }
        /// <summary>
        /// Gets the sender of the event.
        /// </summary>
        public object Param1 { get; internal set; }
        /// <summary>
        /// Gets the arguments of the event.
        /// </summary>
        public object Param2 { get; internal set; }
        /// <summary>
        /// Gets or sets the return value of the event
        /// </summary>
        public object Result { get; set; }

        internal SilverlightEventArgs()
        {
        }
    }

    /// <summary>
    /// Describes the possible types of errors.
    /// </summary>
    public enum ErrorType
    {
        /// <summary>
        /// No error.
        /// </summary>
        NoError,
        /// <summary>
        /// Error is unknown.
        /// </summary>
        UnknownError,
        /// <summary>
        /// Error occurred during initalization.
        /// </summary>
        InitializeError,
        /// <summary>
        /// Error occurred during the parsing of XAML content, at a level before the object
        /// model was incorporated. Examples include tag mismatches in XML.
        /// </summary>
        ParserError,
        /// <summary>
        /// Error occurred during the object model mapping of XAML content. Examples include
        /// name collisions or a required attribute that is missing a value.
        /// </summary>
        ObjectModelError,
        /// <summary>
        /// Error occurred in a synchronous method call inside a JavaScript function.
        /// </summary>
        RuntimeError,
        /// <summary>
        /// Error occurred in a synchronous method call inside a managed function.
        /// </summary>
        ManagedRuntimeError,
        /// <summary>
        /// Error occurred during package downloading.
        /// </summary>
        DownloadError,
        /// <summary>
        /// Error occurred after a media file failed to load.
        /// </summary>
        MediaError,
        /// <summary>
        /// Error occurred after an image file failed to load.
        /// </summary>
        ImageError
    }

    /// <summary>
    /// Describes an error raised from within the XAML DOM of the hosted control.
    /// </summary>
    public class SilverlightErrorEventArgs : EventArgs
    {
        /// <summary>
        /// Gets the name of the error.
        /// </summary>
        public string Error { get; internal set; }
        /// <summary>
        /// Gets the name of the source XAML file.
        /// </summary>
        public string SourceFile { get; internal set; }
        /// <summary>
        /// Gets the line number.
        /// </summary>
        public long Line { get; internal set; }
        /// <summary>
        /// Gets the column number
        /// </summary>
        public long Column { get; internal set; }

        internal SilverlightErrorEventArgs()
        {
        }
    }

    /// <summary>
    /// Describes the download progress.
    /// </summary>
    public class SourceDownloadProgressChangedEventArgs : EventArgs
    {
        /// <summary>
        /// Gets the download progress, expressed as a percentage. Returns a value between 0 and 1,
        /// indicating how much of the document has been downloaded.
        /// </summary>
        public float Progress { get; internal set; }

        internal SourceDownloadProgressChangedEventArgs()
        {
        }
    }

    /// <summary>
    /// Decribes a rendered frame.
    /// </summary>
    public class FrameRenderedEventArgs : EventArgs
    {
        public IntPtr Buffer { get; internal set; }
        public int BufferSize { get; internal set; }
        public int Width { get; internal set; }
        public int Height { get; internal set; }
        public Rectangle DirtyRect { get; internal set; }

        internal FrameRenderedEventArgs()
        {
        }
    }
}

#if WPF
namespace Silverlight.Hosting.Wpf.Private
#else
namespace Silverlight.Hosting.Private
#endif
{
    internal class MaxFrameRateChangedEventArgs : EventArgs
    {
        public int OldValue { get; internal set; }
        public int NewValue { get; internal set; }

        internal MaxFrameRateChangedEventArgs()
        {
        }
    }
}